
//
//  YZQByTurnPicTableViewCell.m
//  SuperNews
//
//  Created by qiang on 16/1/12.
//  Copyright © 2016年 qiang. All rights reserved.
//

#import "YZQByTurnPicTableViewCell.h"
#import "YZQCollectionView.h"


@interface YZQByTurnPicTableViewCell ()
@property (nonatomic, strong) NSMutableArray *picArr;
@property (nonatomic, strong) NSMutableArray *titleArr;
@property (nonatomic, strong) NSMutableArray *urlIdArr;

@property (nonatomic, strong) UIImageView *tempImageView;
@property (nonatomic, strong) UILabel *textL;
@property (nonatomic, strong) UIView *blackView;
@end
@implementation YZQByTurnPicTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setNewsM:(NewsPageModel *)newsM
{
    _newsM = newsM;
    [self getData];
    [self createViews];
}

#pragma mark- 处理数据
- (void)getData
{
    
    NSArray *array = [NSArray array];
    
    array = self.newsM.ads;
    self.picArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray array];
    self.urlIdArr = [NSMutableArray array];
    
    for (NSDictionary *tempDic in array) {
        
        NSString *url = [tempDic objectForKey:@"imgsrc"];
        NSString *title = [tempDic objectForKey:@"title"];
        NSString *urlId = [tempDic objectForKey:@"url"];
        
        [self.picArr addObject:url];
        [self.titleArr addObject:title];
        [self.urlIdArr addObject:urlId];
    }
    
}

- (void)createViews{
    

    [YZQCollectionView collectionViewWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200) imageArray:self.picArr timeInterval:2.0 view:self.contentView];
    
    NSMutableArray *viewArray = [[NSMutableArray alloc] init];
    for (int i = 0; i < self.picArr.count; i++) {
        self.tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 200)];
        
        self.blackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 200)];
        self.blackView.backgroundColor = [UIColor blackColor];
        self.blackView.alpha = 0.3;
        [self.tempImageView addSubview:self.blackView];
        
        // 文字Label
        self.textL = [[UILabel alloc]initWithFrame:CGRectMake(10, 180 - 5, 375 - 100, 20)];
        self.textL.text = self.titleArr[i];
        self.textL.textColor = [UIColor whiteColor];
        self.textL.font = [UIFont systemFontOfSize:15];
        [self.tempImageView addSubview:self.textL];
        
        NSURL *url = [NSURL URLWithString:self.picArr[i]];
        [self.tempImageView sd_setImageWithURL:url placeholderImage:nil];
        
        self.tempImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.tempImageView.clipsToBounds = true;
        [viewArray addObject:self.tempImageView];
        
    }

}


@end
